package ge.unihack.instantdj.utils;

import android.annotation.SuppressLint;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import org.apache.http.conn.util.InetAddressUtils;

public class NetworkUtils {

	@SuppressLint("DefaultLocale")
	public static String getIPAddress() {
		try {
			List<NetworkInterface> interfaces = Collections
					.list(NetworkInterface.getNetworkInterfaces());
			for (NetworkInterface intf : interfaces) {
				List<InetAddress> addrs = Collections.list(intf
						.getInetAddresses());
				for (InetAddress addr : addrs) {
					if (!addr.isLoopbackAddress()) {
						String sAddr = addr.getHostAddress().toUpperCase(Locale.US);
						if (InetAddressUtils.isIPv4Address(sAddr)) {
							return sAddr;
						}
					}
				}
			}
		} catch (Exception ex) {
		}
		return "";
	}
}
